package com.controller.user;

import com.config.RoleInterceptor.Auth;
import com.model.po.User;
import com.model.pojo.RepEntity;
import com.model.pojo.annotation.CheckToken;
import com.model.vo.configVo.LoginInfo;
import com.model.vo.configVo.UserGroupInfo;
import com.model.vo.configVo.UserGroupSetInfo;
import com.server.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
//@RequestMapping("/User")
public class UserController {
    @Autowired
    UserService userService;

    /*
    登录(生成token)
     */
    @RequestMapping("/login")
    public RepEntity login(@RequestBody LoginInfo body){
//        userService.login(body);
        return userService.login(body);
//        return new RepEntity(RepCode.success);
    }

    /*
    更新用户信息
     */
    @Auth(user = "admin")
    @CheckToken
    @RequestMapping("/updateUser")
    public RepEntity updateUser(@RequestHeader String token, @RequestBody User body){
        return userService.updateUser(body);
    }

    /*
    查询用户列表
     */
    @Auth(user = "admin")
    @RequestMapping("/getUserList")
    public RepEntity getUserList(){
        return userService.getUserList();
    }

    /*
    查询匹配用户
     */
    @RequestMapping("/getNameList")
    public RepEntity getNameList(@RequestBody String body){
        return userService.getNameList(body);
    }

    /*
    创建用户组
     */
    @Auth(user = "admin")
    @RequestMapping("/createUserGroup")
    public RepEntity createUserGroup(@RequestBody UserGroupInfo body){
        return userService.createUserGroup(body);
    }

    /*
    更新用户组
     */
    @Auth(user = "admin")
    @RequestMapping("/updateUserGroup")
    public RepEntity updateUserGroup(@RequestBody UserGroupInfo body){
        return userService.updateUserGroup(body);
    }

    /*
    查询用户组列表
     */
    @Auth(user = "admin")
    @RequestMapping("/getUserGroupList")
    public RepEntity getUserGroupList(){
        return userService.getUserGroup();
    }

    /*
    删除用户组
     */
    @Auth(user = "admin")
    @RequestMapping("/delUserGroup")
    public RepEntity delUserGroup(@RequestBody List<Integer> body){
        return userService.delUserGroup(body);
    }

    /*
    用户组添加用户
     */
    @Auth(user = "admin")
    @RequestMapping("/setUserInto")
    public RepEntity setUserInto(@RequestBody UserGroupSetInfo body){
        return userService.setUserInto(body);
    }

    /*
    查询用户组下的用户
     */
    @Auth(user = "admin")
    @RequestMapping("/getUserInGroup")
    public RepEntity getUserInGroup(@RequestBody int body){
        return userService.getUserInGroup(body);
    }

    /*
    删除用户组下的用户
     */
    @Auth(user = "admin")
    @RequestMapping("/delUserInGroup")
    public RepEntity delUserInGroup(@RequestBody UserGroupSetInfo body){
        return userService.delUserInGroup(body);
    }
}
